package com.koron.css2.clientCenter.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.koron.css2.ServerInterface;
import com.koron.css2.clientCenter.bean.NoticeListQueryBean;
import com.koron.css2.clientCenter.mapper.NoticeMapper;
import com.koron.css2.clientCenter.vo.NoticeListVo;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.List;

/**
 * 通知公告列表查询
 * 
 * @author 杨嘉慧
 *
 */
public class NoticeList implements ServerInterface {

	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		try {
			// 将入参转换为Bean
			NoticeListQueryBean nlqBean = JsonUtils.objectToPojo(req.getData(), NoticeListQueryBean.class);
			NoticeMapper noticeMapper = factory.getMapper(NoticeMapper.class);
			PageHelper.startPage(nlqBean.getPage(), nlqBean.getPageCount());
			List<NoticeListVo> noticeList = noticeMapper.noticeList(nlqBean);
			MessageBean<PageInfo> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "查询成功", PageInfo.class);
			info.setData(new PageInfo<>(noticeList));
			return info;
		} catch (Exception e) {
			logger.error("通知公告列表查询失败" + e.getMessage(), e);
			return MessageBean.create(Constant.MESSAGE_INT_FAIL, "查询失败", null);
		}
	}

}
